<?php
/**
 * The controller to manage information of medicine.
 *
 */
class C_Diagnosis extends Controller {
	
	public $template_mod;
	
	function C_Diagnosis($template_mod = "general") {
		parent::Controller();
		if (Celini::getCurrentController() == 'Diagnosis') {
			$menu =& Menu::getInstance();
			$menu->currentSection = 'admin';
		}
		$this->template_mod = $template_mod;				
		$this->view->path = 'diagnosis';
		$this->setLayout('admin');
	}
	
	public function actionManagement() {
		return $this->view->render('management.html');
	}
	
	public function actionList() {
		$list = Celini::newORDO("Diagnosis") -> getDiagnosisList();
		if(count($list) > 0){
			$this->assign('list', $list);
		}
		
		return $this->view->render('list.html');
		
	}
	
	public function actionEdit() {
		$id = $_GET['service_id'];
		$diagnosis = Celini::newORDO('Diagnosis');
		
		if (isset($id) && $id != "") {
			$diagnosis->setup($id);
		}
		
		$this->assign_by_ref('diagnosis', $diagnosis);
		return $this->view->render('edit.html');
		
	}
	
	public function actionSaveAjax() {
	    $locale = L10nHelper::getLocale();
        $field = L10nHelper::changeField($locale, 'name');
	    
		$diagnosis = Celini::newORDO('Diagnosis');
		if (isset($_POST['id']) && $_POST['id'] != 0) {
            $diagnosis->setup($_POST['id']);
       	}       		
		$name		=	Utils::sanitizeText($_POST['name']);
       	
        $l10nData = array();
       	if($diagnosis->get_id() > 0){
       	    $l10nData[$field] = $name;			
        // Add new localized name			
      	} else{
			$supported	=	L10nHelper::getSupportedLocales();
			
			foreach ($supported as $lo	=>	$la){
			    $field = L10nHelper::changeField($lo, 'name');
				$l10nData[$field]	=	$name;
			}
       	}
       	$diagnosis->populateArray($l10nData);
       	$diagnosis->persist();       			
		return $diagnosis->get_id();
	}
	
	public function actionDeleteAjax() {
		$diagnosis = Celini::newORDO('Diagnosis');
		$diagnosis->deleteDiagnosis($_GET['id']);	
	}
}
?>


















